# coding=UTF-8
import wsgiref.handlers
from model.article import Article
from google.appengine.ext import db
from google.appengine.ext import webapp
import datetime
import PyRSS2Gen

class RssGen(webapp.RequestHandler):
    def get(self):
        articles = Article.gql("ORDER BY date DESC limit 10")
        rssItems=[]
        for article in articles:
            rssItems.append(PyRSS2Gen.RSSItem(
                 title = article.title,
                 link = "/viewArticle?key="+article.key().__str__(),
                 description = article.content,
                 guid = PyRSS2Gen.Guid(article.key().__str__()),
                 pubDate = article.date)
                 )
                            
        rss = PyRSS2Gen.RSS2(
            title = "wp 的个人主页",
            link = "http://wpshadow.appspot.com/",
            description = "wp 的个人主页",
            lastBuildDate = datetime.datetime.now(),
            items = rssItems)
        rss.write_xml(self.response.out)
        
    
def main():
  application = webapp.WSGIApplication(
                                       [('/rss.xml', RssGen)
                                        ],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)



if __name__ == "__main__":
  main()
